home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / MPW Interfaces & Libraries / PInterfaces / Sound.p < prev    next >
Encoding:
Text File  |  1992-01-29  |  12.8 KB  |  456 lines  |  [TEXT/MPS ]

  1.  
  2. {
  3. Created: Monday, December 2, 1991 at 5:09 PM
  4.  Sound.p
  5.  Pascal Interface to the Macintosh Libraries
  6.  
  7.   Copyright Apple Computer, Inc. 1986-1991
  8.   All rights reserved
  9. }
  10.  
  11.  
  12. {$IFC UNDEFINED UsingIncludes}
  13. {$SETC UsingIncludes := 0}
  14. {$ENDC}
  15.  
  16. {$IFC NOT UsingIncludes}
  17.  UNIT Sound;
  18.  INTERFACE
  19. {$ENDC}
  20.  
  21. {$IFC UNDEFINED UsingSound}
  22. {$SETC UsingSound := 1}
  23.  
  24. {$I+}
  25. {$SETC SoundIncludes := UsingIncludes}
  26. {$SETC UsingIncludes := 1}
  27. {$IFC UNDEFINED UsingTypes}
  28. {$I $$Shell(PInterfaces)Types.p}
  29. {$ENDC}
  30. {$IFC UNDEFINED UsingFiles}
  31. {$I $$Shell(PInterfaces)Files.p}
  32. {$ENDC}
  33. {$SETC UsingIncludes := SoundIncludes}
  34.  
  35. CONST
  36. swMode = -1;                                { Sound Driver modes }
  37. ftMode = 1;
  38. ffMode = 0;
  39.  
  40. synthCodeRsrc = 'snth';                        { Resource types used by Sound Manager }
  41. soundListRsrc = 'snd ';
  42.  
  43. twelfthRootTwo = 1.05946309434;
  44. rate22khz = $56EE8BA3;                        { 22254.54545 in fixed-point }
  45. rate11khz = $2B7745D1;                        { 11127.27273 in fixed-point }
  46.  
  47. { synthesizer numbers for SndNewChannel }
  48. squareWaveSynth = 1;                        {square wave synthesizer}
  49. waveTableSynth = 3;                            {wave table synthesizer}
  50. sampledSynth = 5;                            {sampled sound synthesizer}
  51.  
  52. { old Sound Manager MACE synthesizer numbers }
  53. MACE3snthID = 11;
  54. MACE6snthID = 13;
  55.  
  56. { command numbers for SndDoCommand and SndDoImmediate }
  57. nullCmd = 0;
  58. initCmd = 1;
  59. freeCmd = 2;
  60. quietCmd = 3;
  61. flushCmd = 4;
  62. reInitCmd = 5;
  63.  
  64. waitCmd = 10;
  65. pauseCmd = 11;
  66. resumeCmd = 12;
  67. callBackCmd = 13;
  68. syncCmd = 14;
  69. emptyCmd = 15;
  70.  
  71. tickleCmd = 20;
  72. requestNextCmd = 21;
  73. howOftenCmd = 22;
  74. wakeUpCmd = 23;
  75. availableCmd = 24;
  76. versionCmd = 25;
  77. totalLoadCmd = 26;
  78. loadCmd = 27;
  79.  
  80. scaleCmd = 30;
  81. tempoCmd = 31;
  82.  
  83. freqDurationCmd = 40;
  84. restCmd = 41;
  85. freqCmd = 42;
  86. ampCmd = 43;
  87. timbreCmd = 44;
  88. getAmpCmd = 45;
  89.  
  90. waveTableCmd = 60;
  91. phaseCmd = 61;
  92.  
  93. soundCmd = 80;
  94. bufferCmd = 81;
  95. rateCmd = 82;
  96. continueCmd = 83;
  97. doubleBufferCmd = 84;
  98. getRateCmd = 85;
  99.  
  100. sizeCmd = 90;
  101. convertCmd = 91;
  102.  
  103. stdQLength = 128;
  104. dataOffsetFlag = $8000;
  105.  
  106. waveInitChannelMask = $07;
  107. waveInitChannel0 = $04;
  108. waveInitChannel1 = $05;
  109. waveInitChannel2 = $06;
  110. waveInitChannel3 = $07;
  111.  
  112. { channel initialization parameters }
  113. initPanMask = $0003;                        { mask for right/left pan values }
  114. initSRateMask = $0030;                        { mask for sample rate values }
  115. initStereoMask = $00C0;                        { mask for mono/stereo values }
  116. initCompMask = $FF00;                        { mask for compression IDs }
  117.  
  118. initChanLeft = $0002;                        { left stereo channel }
  119. initChanRight = $0003;                        { right stereo channel }
  120. initNoInterp = $0004;                        { no linear interpolation }
  121. initNoDrop = $0008;                            { no drop-sample conversion }
  122. initMono = $0080;                            { monophonic channel }
  123. initStereo = $00C0;                            { stereo channel }
  124. initMACE3 = $0300;                            { MACE 3:1 }
  125. initMACE6 = $0400;                            { MACE 6:1 }
  126.  
  127. initChan0 = $0004;                            { channel 0 - wave table only }
  128. initChan1 = $0005;                            { channel 1 - wave table only }
  129. initChan2 = $0006;                            { channel 2 - wave table only }
  130. initChan3 = $0007;                            { channel 3 - wave table only }
  131.  
  132. stdSH = $00;                                { Standard sound header encode value }
  133. extSH = $FF;                                { Extended sound header encode value }
  134. cmpSH = $FE;                                { Compressed sound header encode value }
  135.  
  136. notCompressed = 0;                            { compression ID's }
  137. twoToOne = 1;
  138. eightToThree = 2;
  139. threeToOne = 3;
  140. sixToOne = 4;
  141.  
  142. outsideCmpSH = 0;                            { MACE constants }
  143. insideCmpSH = 1;
  144. aceSuccess = 0;
  145. aceMemFull = 1;
  146. aceNilBlock = 2;
  147. aceBadComp = 3;
  148. aceBadEncode = 4;
  149. aceBadDest = 5;
  150. aceBadCmd = 6;
  151. sixToOnePacketSize = 8;
  152. threeToOnePacketSize = 16;
  153. stateBlockSize = 64;
  154. leftOverBlockSize = 32;
  155.  
  156. firstSoundFormat = $0001;                    { general sound format }
  157. secondSoundFormat = $0002;                    { special sampled sound format (HyperCard) }
  158.  
  159. dbBufferReady = $00000001;                    { double buffer is filled }
  160. dbLastBuffer = $00000004;                    { last double buffer to play }
  161.  
  162. sysBeepDisable = $0000;                        { SysBeep() enable flags }
  163. sysBeepEnable = $0001;
  164.  
  165. unitTypeNoSelection = $FFFF;                { unitTypes for AudioSelection.unitType }
  166. unitTypeSeconds = $0000;
  167.  
  168. TYPE
  169. {   Structures for Sound Driver   }
  170.  
  171.  
  172. FreeWave = PACKED ARRAY [0..30000] OF Byte;
  173.  
  174. FFSynthPtr = ^FFSynthRec;
  175. FFSynthRec = RECORD
  176.  mode: INTEGER;
  177.  count: Fixed;
  178.  waveBytes: FreeWave;
  179.  END;
  180.  
  181. Tone = RECORD
  182.  count: INTEGER;
  183.  amplitude: INTEGER;
  184.  duration: INTEGER;
  185.  END;
  186.  
  187.  
  188. Tones = ARRAY [0..5000] OF Tone;
  189.  
  190. SWSynthPtr = ^SWSynthRec;
  191. SWSynthRec = RECORD
  192.  mode: INTEGER;
  193.  triplets: Tones;
  194.  END;
  195.  
  196.  
  197. Wave = PACKED ARRAY [0..255] OF Byte;
  198. WavePtr = ^Wave;
  199.  
  200. FTSndRecPtr = ^FTSoundRec;
  201. FTSoundRec = RECORD
  202.  duration: INTEGER;
  203.  sound1Rate: Fixed;
  204.  sound1Phase: LONGINT;
  205.  sound2Rate: Fixed;
  206.  sound2Phase: LONGINT;
  207.  sound3Rate: Fixed;
  208.  sound3Phase: LONGINT;
  209.  sound4Rate: Fixed;
  210.  sound4Phase: LONGINT;
  211.  sound1Wave: WavePtr;
  212.  sound2Wave: WavePtr;
  213.  sound3Wave: WavePtr;
  214.  sound4Wave: WavePtr;
  215.  END;
  216.  
  217. FTSynthPtr = ^FTSynthRec;
  218. FTSynthRec = RECORD
  219.  mode: INTEGER;
  220.  sndRec: FTSndRecPtr;
  221.  END;
  222.  
  223. {   Structures for Sound Manager   }
  224.  
  225. SndCommand = PACKED RECORD
  226.  cmd: INTEGER;
  227.  param1: INTEGER;
  228.  param2: LONGINT;
  229.  END;
  230.  
  231.  
  232. Time = LONGINT;                                { in half milliseconds }
  233.  
  234.  
  235.  
  236. SndChannelPtr = ^SndChannel;
  237. SndChannel = PACKED RECORD
  238.  nextChan: SndChannelPtr;
  239.  firstMod: Ptr;                                { reserved for the Sound Manager }
  240.  callBack: ProcPtr;
  241.  userInfo: LONGINT;
  242.  wait: Time;                                { The following is for internal Sound Manager use only.}
  243.  cmdInProgress: SndCommand;
  244.  flags: INTEGER;
  245.  qLength: INTEGER;
  246.  qHead: INTEGER;                            { next spot to read or -1 if empty }
  247.  qTail: INTEGER;                            { next spot to write = qHead if full }
  248.  queue: ARRAY [0..stdQLength - 1] OF SndCommand;
  249.  END;
  250.  
  251. { MACE structures }
  252. StateBlockPtr = ^StateBlock;
  253. StateBlock = RECORD
  254.  stateVar: ARRAY [0..stateBlockSize - 1] OF INTEGER;
  255.  END;
  256.  
  257. LeftOverBlockPtr = ^LeftOverBlock;
  258. LeftOverBlock = RECORD
  259.  count: LONGINT;
  260.  sampleArea: PACKED ARRAY [0..leftOverBlockSize - 1] OF Byte;
  261.  END;
  262.  
  263. ModRef = RECORD
  264.  modNumber: INTEGER;
  265.  modInit: LONGINT;
  266.  END;
  267.  
  268. SndListPtr = ^SndListResource;
  269. SndListResource = RECORD
  270.  format: INTEGER;
  271.  numModifiers: INTEGER;
  272.  modifierPart: ARRAY [0..0] OF ModRef;        {This is a variable length array}
  273.  numCommands: INTEGER;
  274.  commandPart: ARRAY [0..0] OF SndCommand;    {This is a variable length array}
  275.  dataPart: PACKED ARRAY [0..0] OF Byte;        {This is a variable length array}
  276.  END;
  277.  
  278. SoundHeaderPtr = ^SoundHeader;
  279. SoundHeader = PACKED RECORD
  280.  samplePtr: Ptr;                            { if NIL then samples are in sampleArea }
  281.  length: LONGINT;                            { length of sound in bytes }
  282.  sampleRate: Fixed;                            { sample rate for this sound }
  283.  loopStart: LONGINT;                        { start of looping portion }
  284.  loopEnd: LONGINT;                            { end of looping portion }
  285.  encode: Byte;                                { header encoding }
  286.  baseFrequency: Byte;                        { baseFrequency value }
  287.  sampleArea: PACKED ARRAY [0..0] OF Byte;
  288.  END;
  289.  
  290. CmpSoundHeaderPtr = ^CmpSoundHeader;
  291. CmpSoundHeader = PACKED RECORD
  292.  samplePtr: Ptr;                            { if nil then samples are in sample area }
  293.  numChannels: LONGINT;                        { number of channels i.e. mono = 1 }
  294.  sampleRate: Fixed;                            { sample rate in Apples Fixed point representation }
  295.  loopStart: LONGINT;                        { loopStart of sound before compression }
  296.  loopEnd: LONGINT;                            { loopEnd of sound before compression }
  297.  encode: Byte;                                { data structure used , stdSH, extSH, or cmpSH }
  298.  baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  299.  numFrames: LONGINT;                        { length in frames ( packetFrames or sampleFrames ) }
  300.  AIFFSampleRate: Extended80;                { IEEE sample rate }
  301.  markerChunk: Ptr;                            { sync track }
  302.  futureUse1: Ptr;                            { reserved by Apple }
  303.  futureUse2: Ptr;                            { reserved by Apple }
  304.  stateVars: StateBlockPtr;                    { pointer to State Block }
  305.  leftOverSamples: LeftOverBlockPtr;            { used to save truncated samples between compression calls }
  306.  compressionID: INTEGER;                    { 0 means no compression, non zero means compressionID }
  307.  packetSize: INTEGER;                        { number of bits in compressed sample packet }
  308.  snthID: INTEGER;                            { resource ID of Sound Manager snth that contains NRT C/E }
  309.  sampleSize: INTEGER;                        { number of bits in non-compressed sample }
  310.  sampleArea: PACKED ARRAY [0..0] OF Byte;    { space for when samples follow directly }
  311.  END;
  312.  
  313. ExtSoundHeaderPtr = ^ExtSoundHeader;
  314. ExtSoundHeader = PACKED RECORD
  315.  samplePtr: Ptr;                            { if nil then samples are in sample area }
  316.  numChannels: LONGINT;                        { number of channels,  ie mono = 1 }
  317.  sampleRate: Fixed;                            { sample rate in Apples Fixed point representation }
  318.  loopStart: LONGINT;                        { same meaning as regular SoundHeader }
  319.  loopEnd: LONGINT;                            { same meaning as regular SoundHeader }
  320.  encode: Byte;                                { data structure used , stdSH, extSH, or cmpSH }
  321.  baseFrequency: Byte;                        { same meaning as regular SoundHeader }
  322.  numFrames: LONGINT;                        { length in total number of frames }
  323.  AIFFSampleRate: Extended80;                { IEEE sample rate }
  324.  markerChunk: Ptr;                            { sync track }
  325.  instrumentChunks: Ptr;                        { AIFF instrument chunks }
  326.  AESRecording: Ptr;
  327.  sampleSize: INTEGER;                        { number of bits in sample }
  328.  futureUse1: INTEGER;                        { reserved by Apple }
  329.  futureUse2: LONGINT;                        { reserved by Apple }
  330.  futureUse3: LONGINT;                        { reserved by Apple }
  331.  futureUse4: LONGINT;                        { reserved by Apple }
  332.  sampleArea: PACKED ARRAY [0..0] OF Byte;    { space for when samples follow directly }
  333.  END;
  334.  
  335. ConversionBlockPtr = ^ConversionBlock;
  336. ConversionBlock = RECORD
  337.  destination: INTEGER;
  338.  unused: INTEGER;
  339.  inputPtr: CmpSoundHeaderPtr;
  340.  outputPtr: CmpSoundHeaderPtr;
  341.  END;
  342.  
  343. SMStatusPtr = ^SMStatus;
  344. SMStatus = PACKED RECORD
  345.  smMaxCPULoad: INTEGER;
  346.  smNumChannels: INTEGER;
  347.  smCurCPULoad: INTEGER;
  348.  END;
  349.  
  350. SCStatusPtr = ^SCStatus;
  351. SCStatus = RECORD
  352.  scStartTime: Fixed;
  353.  scEndTime: Fixed;
  354.  scCurrentTime: Fixed;
  355.  scChannelBusy: BOOLEAN;
  356.  scChannelDisposed: BOOLEAN;
  357.  scChannelPaused: BOOLEAN;
  358.  scUnused: BOOLEAN;
  359.  scChannelAttributes: LONGINT;
  360.  scCPULoad: LONGINT;
  361.  END;
  362.  
  363. AudioSelectionPtr = ^AudioSelection;
  364. AudioSelection = PACKED RECORD
  365.  unitType: LONGINT;
  366.  selStart: Fixed;
  367.  selEnd: Fixed;
  368.  END;
  369.  
  370. SndDoubleBufferPtr = ^SndDoubleBuffer;
  371. SndDoubleBuffer = PACKED RECORD
  372.  dbNumFrames: LONGINT;
  373.  dbFlags: LONGINT;
  374.  dbUserInfo: ARRAY [0..1] OF LONGINT;
  375.  dbSoundData: PACKED ARRAY [0..0] OF Byte;
  376.  END;
  377.  
  378. SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
  379. SndDoubleBufferHeader = PACKED RECORD
  380.  dbhNumChannels: INTEGER;
  381.  dbhSampleSize: INTEGER;
  382.  dbhCompressionID: INTEGER;
  383.  dbhPacketSize: INTEGER;
  384.  dbhSampleRate: Fixed;
  385.  dbhBufferPtr: ARRAY [0..1] OF SndDoubleBufferPtr;
  386.  dbhDoubleBack: ProcPtr;
  387.  END;
  388.  
  389.  
  390. FUNCTION SndDoCommand(chan: SndChannelPtr;cmd: SndCommand;noWait: BOOLEAN): OSErr;
  391.  INLINE $A803;
  392. FUNCTION SndDoImmediate(chan: SndChannelPtr;cmd: SndCommand): OSErr;
  393.  INLINE $A804;
  394. FUNCTION SndNewChannel(VAR chan: SndChannelPtr;synth: INTEGER;init: LONGINT;
  395.  userRoutine: ProcPtr): OSErr;
  396.  INLINE $A807;
  397. FUNCTION SndDisposeChannel(chan: SndChannelPtr;quietNow: BOOLEAN): OSErr;
  398.  INLINE $A801;
  399. FUNCTION SndPlay(chan: SndChannelPtr;sndHdl: Handle;async: BOOLEAN): OSErr;
  400.  INLINE $A805;
  401. FUNCTION SndAddModifier(chan: SndChannelPtr;modifier: ProcPtr;id: INTEGER;
  402.  init: LONGINT): OSErr;
  403.  INLINE $A802;
  404. FUNCTION SndControl(id: INTEGER;VAR cmd: SndCommand): OSErr;
  405.  INLINE $A806;
  406.  
  407. PROCEDURE SetSoundVol(level: INTEGER);
  408. PROCEDURE GetSoundVol(VAR level: INTEGER);
  409. PROCEDURE StartSound(synthRec: Ptr;numBytes: LONGINT;completionRtn: ProcPtr);
  410. PROCEDURE StopSound;
  411. FUNCTION SoundDone: BOOLEAN;
  412.  
  413. FUNCTION SndSoundManagerVersion: NumVersion;
  414.  INLINE $203C,$000C,$0008,$A800;
  415. FUNCTION SndStartFilePlay(chan: SndChannelPtr;fRefNum: INTEGER;resNum: INTEGER;
  416.  bufferSize: LONGINT;theBuffer: Ptr;theSelection: AudioSelectionPtr;theCompletion: ProcPtr;
  417.  async: BOOLEAN): OSErr;
  418.  INLINE $203C,$0D00,$0008,$A800;
  419. FUNCTION SndPauseFilePlay(chan: SndChannelPtr): OSErr;
  420.  INLINE $203C,$0204,$0008,$A800;
  421. FUNCTION SndStopFilePlay(chan: SndChannelPtr;async: BOOLEAN): OSErr;
  422.  INLINE $203C,$0308,$0008,$A800;
  423. FUNCTION SndChannelStatus(chan: SndChannelPtr;theLength: INTEGER;theStatus: SCStatusPtr): OSErr;
  424.  INLINE $203C,$0010,$0008,$A800;
  425. FUNCTION SndManagerStatus(theLength: INTEGER;theStatus: SMStatusPtr): OSErr;
  426.  INLINE $203C,$0014,$0008,$A800;
  427. PROCEDURE SndGetSysBeepState(VAR sysBeepState: INTEGER);
  428.  INLINE $203C,$0018,$0008,$A800;
  429. FUNCTION SndSetSysBeepState(sysBeepState: INTEGER): OSErr;
  430.  INLINE $203C,$001C,$0008,$A800;
  431. FUNCTION SndPlayDoubleBuffer(chan: SndChannelPtr;theParams: SndDoubleBufferHeaderPtr): OSErr;
  432.  INLINE $203C,$0020,$0008,$A800;
  433.  
  434. FUNCTION MACEVersion: NumVersion;
  435.  INLINE $203C,$0000,$0010,$A800;
  436. PROCEDURE Comp3to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  437.  outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  438.  INLINE $203C,$0004,$0010,$A800;
  439. PROCEDURE Exp1to3(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  440.  outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  441.  INLINE $203C,$0008,$0010,$A800;
  442. PROCEDURE Comp6to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  443.  outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  444.  INLINE $203C,$000C,$0010,$A800;
  445. PROCEDURE Exp1to6(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  446.  outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  447.  INLINE $203C,$0010,$0010,$A800;
  448.  
  449.  
  450. {$ENDC} { UsingSound }
  451.  
  452. {$IFC NOT UsingIncludes}
  453.  END.
  454. {$ENDC}
  455.  
  456.